USE [SONALIKA_BGK_UPDATED]
GO

/****** Object:  StoredProcedure [dbo].[SpSparePurchaseByInvoiceId]    Script Date: 05/25/2014 16:58:05 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SpSparePurchaseByInvoiceId]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SpSparePurchaseByInvoiceId]
GO

USE [SONALIKA_BGK_UPDATED]
GO

/****** Object:  StoredProcedure [dbo].[SpSparePurchaseByInvoiceId]    Script Date: 05/25/2014 16:58:05 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




CREATE PROC [dbo].[SpSparePurchaseByInvoiceId] --2
(@INVOICE_ID INT)
AS
BEGIN
SELECT 
         VAT_PERCENT
        ,INVOICE_DISCOUNT
        ,INVOICE_GRANDTOTAL
         ,SPS.SALES_INVOICE_ID
         ,QUANTITY
         ,SPARE_PART_CODE
         ,SPARE_PART_DESCRIPTION
         ,INVOICE_NO
          ,replace(convert(NVARCHAR, INVOICE_DATE, 106), ' ', '-')AS INVOICE_DATE 
         ,I.INVOICE_ID
         ,EXPENDITURE_ON_SUBTOAL as EXPENDITURE
         ,[SPARE_UNIT_COST]AS UNIT_COST

	 
          
 FROM SPARE_PURCHASES_SALES SPS
  LEFT OUTER JOIN INVOICE I ON I.INVOICE_ID=SPS.INVOICE_ID
  LEFT OUTER JOIN SPARE_PARTS SP ON SP.SPARE_PART_ID=SPS.SPARE_PART_ID

  
            
 WHERE I.INVOICE_ID=@INVOICE_ID 
     
END



GO


